//************************************************************
//	COPYRIGHT 2011 Birthin' Hips - ALL RIGHTS RESERVED
//************************************************************
//
//	$Id: MessageCreator.java$
//
//	$Date: 12/13/11$
//
//	Reason: Acts as a factory for generating PositionUpdate and StatusUpdate Messages.
//
//*************************************************************

/** $Author: Colton Presler, Ross Kahn, Elysia Haight$ */
/** $Revision: $ */

package com;

import java.util.Random;

//==============================================================
public class MessageCreator {

	private String baseStatus;		// String printed for each StatusUpdate message key, followed by an incremental number
	private String baseValue;		// String printed for each StatusUpdate message value, followed by an incremental number
	private int statusIncrement;	// Incremental number, starting at 1, to identify StatusUpdate messages from one another
	private int posValMax;			// Maximum value for each of the PositionUpdate integers (generated at random)
	private Random rand;			// Random number generator for the PositionUpdate integers
	
	
	/**
	 * Class constructor. Initializes all of the basic Message details sent to created Messages 
	 */
	//----------------------------------------------------------
	public MessageCreator(){
		baseStatus = "status";
		baseValue = "value";
		statusIncrement = 0;
		posValMax = 100;
		rand = new Random();
	}
	
	/**
	 * Public method to return a random message of either PositionUpdate or StatusUpdate type. 
	 * @return		Randomly chosen and created Message subclass
	 */
	//----------------------------------------------------------
	public Message createMessage(){
		int toCreate = rand.nextInt(2);
		
		if(toCreate == 0){
			return createPositionMessage();
		}else{
			return createStatusMessage();
		}
	}
	
	/**
	 * Generates a PositionUpdate message with randomly chosen numbers from 0-posValMax
	 * @return	Randomly generated PositionUpdate
	 */
	//----------------------------------------------------------
	private PositionUpdate createPositionMessage(){
		return new PositionUpdate(rand.nextInt(posValMax),rand.nextInt(posValMax),
				rand.nextInt(posValMax),rand.nextInt(posValMax));
	}
	
	/**
	 * Generates a StatusUpdate message with the current increment number
	 * @return	A newly incremented StatusUpdate 
	 */
	//----------------------------------------------------------
	private StatusUpdate createStatusMessage(){
		statusIncrement++;
		return new StatusUpdate(baseStatus + statusIncrement, baseValue+statusIncrement);
	}
}
